package com;

import com.mapper.StudentsMapper;
import com.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

public class Students {
    @Test
    public void selectStudentsByIdTest(){
        SqlSession session = MyBatisUtils.getSession();
        StudentsMapper mapper = session.getMapper(StudentsMapper.class);
        com.pojo.Students students = mapper.selectStudentById(2);
        System.out.println(students);
        session.close();
    }

    @Test
    public void updateStudentsTest(){
        SqlSession session = MyBatisUtils.getSession();
        StudentsMapper mapper = session.getMapper(StudentsMapper.class);
        com.pojo.Students students = new com.pojo.Students();
        students.setId(4);
        students.setName("李雷");
        students.setAge(21);
        int result = mapper.updateStudents(students);
        if (result>0){
            System.out.println("成功插入"+result+"条数据");
        }else {
            System.out.println("插入数据失败");
        }
        System.out.println(students.toString());
        session.commit();
        session.close();
    }
}
